import {useNavigate} from "react-router-dom";
import {useState} from "react";

export default function Time() {
    const navigate = useNavigate()
    // 返回
    function goBack(path) {
        return () => navigate(path)
    }

    // 倒计时
    let [dTime, setTime] = useState(getNewTime())

    function getNewTime() {
        return new Date().toLocaleString()
    }

    // 更新当前时间
    function timeUp() {
        setInterval(() => {
            setTime(getNewTime)
        })
    }

    timeUp()


    return (
        <>
            <div>
                {dTime}
            </div>
            <div>time页面</div>
            <button onClick={goBack('/')}>
                返回首页
            </button>
        </>
    )
}